//
//  AMLoginController.m
//  WeiDu_1_0
//
//  Created by foguo-mac-1 on 01/07/16.
//  Copyright (c) 2016 WeiDu Energy Tech. All rights reserved.
//

#import "HOUserInfoController.h"
#import "HORequestFactory.h"
#import "HOConstants.h"
#import "HOUIMgr.h"
#import "Logger.h"
#import "HOUserInfoDataModule.h"

@implementation HOUserInfoController

- (void)handleResponseLogic:(HOBaseResponseEntity *)response
{
    if([response.action isEqualToString:kHO_ACTION_Login]
       || [response.action isEqualToString:kHO_ACTION_MobileReg])
    {
//		NSString *token = ((HOUserInfoDataModule *)dataModule).token;
		NSString *token = [response.dataNode objectForKey:kHO_FIELD_Token];
		NSString *rongyunToken = [response.dataNode objectForKey:kHO_FIELD_TokenRongyun];
		HO_USER_TYPE userType = [[response.baseRequest.params objectForKey:kHO_FIELD_UserType] intValue];
		[((HOUserInfoDataModule *)dataModule) saveToken:token
									   withRongyunToken:rongyunToken
										   withUserType:userType];
        if(token != nil && token.length > 0)
        {
            [[HOUIMgr sharedInstance] didLogin];
        }
    }
    
}

- (void)saveUserType:(HO_USER_TYPE)userType
{
	return [(HOUserInfoDataModule *)[self getDataModule] saveUserType:userType];
}

- (HO_USER_TYPE)getUserType
{
	return [(HOUserInfoDataModule *)[self getDataModule] getUserType];
}
- (NSString *)getToken
{
	return [(HOUserInfoDataModule *)[self getDataModule] getToken];
}
- (NSString *)getRongyunToken
{
	return [(HOUserInfoDataModule *)[self getDataModule] getRongyunToken];
}

- (void)didReceiveCommand:(NSString *)action data:(id)data
{
    [super didReceiveCommand:action data:data];
    if([action isEqualToString:kHO_CMD_Got_JPush_RegistrationID])
    {
    }
    [super didReceiveCommand:action data:data];
}

- (void)logout
{
    [(HOUserInfoDataModule *)[self getDataModule] logout];
}



- (void)didLogin
{
    [[self getDataModule] didLogin];
}
@end
